#ifndef __STDIO_GETS_H__
#define __STDIO_GETS_H__

#include <stdio/getchar.h>
#include <stdio/putchar.h>

/**
 *  gets()
 *  sejme string z klavesnice o maximalni delce <size>, kazdy znak vytiskne na STDOUT
 */
char *gets(char *cs) {
  unsigned int counter = 0;
  unsigned char c = '\0';
  char *s;

  s = cs;
  while (1) {
    c = getchar();
    if(c == '\r') break;
    if(c == '\n') break;
    if(c == '\0') break;
    if(c == '\t') c = ' ';

      if(!(counter == 0 && c == '\b'))
        putchar(c);

      if(c == '\b') {
        if (counter > 0)
        counter--;
      }
      else
        *(s+(counter++)) = c;
  }
  putchar('\n');
  *(s+(counter++)) = '\0';
  return s;
}

#endif
